package org.metasketch.editor.toolbox;

import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import org.metasketch.editor.Project;
import org.metasketch.graphics.Diagram;

public abstract class BaseDiagramType implements IDiagramType {

	protected IDiagramBuilder diagramBuilder;
	
	protected String name;

	public BaseDiagramType(String name, IDiagramBuilder diagramBuilder) {
		this.name = name;
		this.diagramBuilder = diagramBuilder;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public Diagram create() {
		Diagram diagram = new Diagram();
		diagram.setType(name);

		return diagram;
	}

	@Override
	public boolean isCompatible(String type) {
		return type.equals(name);
	}
	
	protected ToggleButton createButton(String name, ToggleGroup group, String data){
		ToggleButton tg = new ToggleButton(name);
		tg.setToggleGroup(group);
		tg.setUserData(data);
		
		
		tg.setMaxWidth(120);
		tg.setMinWidth(120);
		tg.setPrefWidth(120);
		
		return tg;
	}

	
	@Override
	public Object createGraphicalDiagram(Diagram diagram, Project project) throws Throwable {
		return diagramBuilder.getJFXDiagram(diagram, project);
	}
	
}
